//路由配置信息
import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
import myOrder from '@/pages/Center/myOrder'
import groupOrder from '@/pages/Center/groupOrder'
export default [
    {
        path: '/center',
        component: Center,
        meta: { show: true },
        children: [
            {
                path: 'myorder',
                component: myOrder,
            }, 
            {
                path: 'grouporder',
                component: groupOrder,
            },
            {
                path: '/center',
               redirect:'/center/myorder'
            }
        ]
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
        meta: { show: true },
    },
    {
        path: '/pay',
        component: Pay,
        meta: { show: true },
        // 将query参数映射成props传递给路由组件
    props: route => ({orderId: route.query.orderId}),

    /* 只能从交易界面, 才能跳转到支付界面 */
    beforeEnter (to, from, next) {
      if (from.path==='/trade') {
        next()
      } else {
        next('/trade')
      }
    }
    },

    {
        path: "/trade",
        component: Trade,
        meta: { show: true },
        /* 只能从购物车界面, 才能跳转到交易界面 */
    beforeEnter (to, from, next) {
        if (from.path==='/shopcart') {
          next()
        } else {
          next('/shopcart')
        }
      }
    },
    {
        path: "/shopcart",
        component: ShopCart,
        meta: { show: true },
    },
    {
        path: "/addcartsuccess",
        name: 'addcartsuccess',
        component: AddCartSuccess,
        meta: { show: true },
    },
    {
        path: "/detail/:skuid",
        component: Detail,
        meta: { show: true },
    },
    {
        path: "/home",
        component: Home,
        meta: { show: true }
    },
    {
        path: "/login",
        component: Login,
        meta: { show: false }
    },
    {
        path: "/register",
        component: Register,
        meta: { show: false }
    },
    {

        path: "/search/:keyword?",
        component: Search,
        meta: { show: true },
        name: "search",
        /*  props:($route)=>{
             return{
                 keyword:$route.params.keyword,
                 k:$route.query.k
 
             }
         } */
    },
    //重定向
    {
        path: '*',
        reactive: '/home'
    }

]